package com.gp.sys.domain;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import org.springframework.security.GrantedAuthority;
import org.springframework.security.GrantedAuthorityImpl;
import org.springframework.security.userdetails.UserDetails;

import com.gp.base.BaseDomain;

/**
 * SysUser entity. @author MyEclipse Persistence Tools
 */

public class SysUser extends BaseDomain implements java.io.Serializable, UserDetails  {

	// Fields

	private String id;
	private String regNo;
	private String nickName;
	private String realName;
	private String password;
	private String areaName;
	private String addr;
	private String email;
	private String sex;
	private String idCardNo;
	private String birth;
	private String telphone;
	private String qqNo;
	private String msnNo;
	private String ucNo;
	private String heigth;
	private String weigth;
	private String hatSize;
	private String trousersSize;
	private String wearSize;
	private String shoesSize;
	private String hoseSize;
	private String gloveSize;
	private String kneepadSize;
	private String cuffSize;
	private String remark;
	private String status;
	private Timestamp regDate;
	private String auditor;
	private Timestamp auditDate;
	private String lastUpdater;
	private Timestamp lastUpdaterDate;
	private String deleteFlag;

	private List<SysRole> sysRoles = new ArrayList<SysRole>();
	// Constructors

	/** default constructor */
	public SysUser() {
	}

	/** minimal constructor */
	public SysUser(String id, String regNo, String nickName, String realName,
			String sex) {
		this.id = id;
		this.regNo = regNo;
		this.nickName = nickName;
		this.realName = realName;
		this.sex = sex;
	}

	/** full constructor */
	public SysUser(String id, String regNo, String nickName, String realName,
			String password, String areaName, String addr, String email,
			String sex, String idCardNo, String birth,
			String telphone, String qqNo, String msnNo, String ucNo,String heigth, 
			String weigth, String hatSize,String trousersSize, String wearSize, 
			String shoesSize,String hoseSize, String gloveSize, String kneepadSize,
			String cuffSize, String remark, String status, Timestamp regDate,
			String auditor, Timestamp auditDate, String lastUpdater,
			Timestamp lastUpdaterDate, String deleteFlag) {
		this.id = id;
		this.regNo = regNo;
		this.nickName = nickName;
		this.realName = realName;
		this.password = password;
		this.areaName = areaName;
		this.addr = addr;
		this.email = email;
		this.sex = sex;
		this.idCardNo = idCardNo;
		this.birth = birth;
		this.telphone = telphone;
		this.qqNo = qqNo;
		this.msnNo = msnNo;
		this.ucNo = ucNo;
		this.heigth = heigth;
		this.weigth = weigth;
		this.hatSize = hatSize;
		this.trousersSize = trousersSize;
		this.wearSize = wearSize;
		this.shoesSize = shoesSize;
		this.hoseSize = hoseSize;
		this.gloveSize = gloveSize;
		this.kneepadSize = kneepadSize;
		this.cuffSize = cuffSize;
		this.remark = remark;
		this.status = status;
		this.regDate = regDate;
		this.auditor = auditor;
		this.auditDate = auditDate;
		this.lastUpdater = lastUpdater;
		this.lastUpdaterDate = lastUpdaterDate;
		this.deleteFlag = deleteFlag;
	}

	// Property accessors

	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getRegNo() {
		return this.regNo;
	}

	public void setRegNo(String regNo) {
		this.regNo = regNo;
	}

	public String getNickName() {
		return this.nickName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	public String getRealName() {
		return this.realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getAreaName() {
		return this.areaName;
	}

	public void setAreaName(String areaName) {
		this.areaName = areaName;
	}

	public String getAddr() {
		return this.addr;
	}

	public void setAddr(String addr) {
		this.addr = addr;
	}

	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getSex() {
		return this.sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getIdCardNo() {
		return this.idCardNo;
	}

	public void setIdCardNo(String idCardNo) {
		this.idCardNo = idCardNo;
	}

	public String getBirth() {
		return this.birth;
	}

	public void setBirth(String birth) {
		this.birth = birth;
	}

	public String getTelphone() {
		return this.telphone;
	}

	public void setTelphone(String telphone) {
		this.telphone = telphone;
	}

	public String getQqNo() {
		return this.qqNo;
	}

	public void setQqNo(String qqNo) {
		this.qqNo = qqNo;
	}

	public String getMsnNo() {
		return this.msnNo;
	}

	public void setMsnNo(String msnNo) {
		this.msnNo = msnNo;
	}

	public String getUcNo() {
		return this.ucNo;
	}

	public void setUcNo(String ucNo) {
		this.ucNo = ucNo;
	}

	public String getHeigth() {
		return this.heigth;
	}

	public void setHeigth(String heigth) {
		this.heigth = heigth;
	}

	public String getWeigth() {
		return this.weigth;
	}

	public void setWeigth(String weigth) {
		this.weigth = weigth;
	}

	public String getHatSize() {
		return this.hatSize;
	}

	public void setHatSize(String hatSize) {
		this.hatSize = hatSize;
	}

	public String getTrousersSize() {
		return this.trousersSize;
	}

	public void setTrousersSize(String trousersSize) {
		this.trousersSize = trousersSize;
	}

	public String getWearSize() {
		return this.wearSize;
	}

	public void setWearSize(String wearSize) {
		this.wearSize = wearSize;
	}

	public String getShoesSize() {
		return this.shoesSize;
	}

	public void setShoesSize(String shoesSize) {
		this.shoesSize = shoesSize;
	}

	public String getHoseSize() {
		return this.hoseSize;
	}

	public void setHoseSize(String hoseSize) {
		this.hoseSize = hoseSize;
	}

	public String getGloveSize() {
		return this.gloveSize;
	}

	public void setGloveSize(String gloveSize) {
		this.gloveSize = gloveSize;
	}

	public String getKneepadSize() {
		return this.kneepadSize;
	}

	public void setKneepadSize(String kneepadSize) {
		this.kneepadSize = kneepadSize;
	}

	public String getCuffSize() {
		return this.cuffSize;
	}

	public void setCuffSize(String cuffSize) {
		this.cuffSize = cuffSize;
	}

	public String getRemark() {
		return this.remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String getStatus() {
		return this.status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public Timestamp getRegDate() {
		return this.regDate;
	}

	public void setRegDate(Timestamp regDate) {
		this.regDate = regDate;
	}

	public String getAuditor() {
		return this.auditor;
	}

	public void setAuditor(String auditor) {
		this.auditor = auditor;
	}

	public Timestamp getAuditDate() {
		return this.auditDate;
	}

	public void setAuditDate(Timestamp auditDate) {
		this.auditDate = auditDate;
	}

	public String getLastUpdater() {
		return this.lastUpdater;
	}

	public void setLastUpdater(String lastUpdater) {
		this.lastUpdater = lastUpdater;
	}

	public Timestamp getLastUpdaterDate() {
		return this.lastUpdaterDate;
	}

	public void setLastUpdaterDate(Timestamp lastUpdaterDate) {
		this.lastUpdaterDate = lastUpdaterDate;
	}

	public String getDeleteFlag() {
		return this.deleteFlag;
	}

	public void setDeleteFlag(String deleteFlag) {
		this.deleteFlag = deleteFlag;
	}

	public List<SysRole> getSysRoles() {
		return sysRoles;
	}

	public void setSysRoles(List<SysRole> sysRoles) {
		this.sysRoles = sysRoles;
	}

	@Override
	public GrantedAuthority[] getAuthorities() {
		List<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>(sysRoles.size());   
        for(SysRole role : sysRoles) {   
            grantedAuthorities.add(new GrantedAuthorityImpl(role.getRoleNo()));   
        }   
        return grantedAuthorities.toArray(new GrantedAuthority[sysRoles.size()]);   
	}

	@Override
	public String getUsername() {
		return this.regNo;
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return ! "9".equals(this.status);
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		if(! "2".equals(this.status)){
			return false;
		}
		return ! "1".equals(this.deleteFlag);
	}

	
}